***generates rate spread graphs over time
use "$data/demog_meta.dta", clear

*drop top outliers
egen p999=pctile(loan_amount), p(99.9)
drop if rate_spread>p999

**Above 50k
*creat treatment and control groups
gen above=.
replace above=0 if rate_spread<5.75&rate_spread>0&loan_amount>=50
replace above=1 if rate_spread>=5.75&rate_spread<12&loan_amount>=50

binscatter rate_spread as_of if as_of>=2010, by(above) line(connect) xline(2014) ytitle(Interest Rate Spread) xtitle(Year)/*
*/ legend(label(1 "Rate Spread<5.75") label(2 "Rate Spread>5.75")) yscale(r(1.5 8)) ylabel(2(1)8)
graph export "$figures/figure3_panelc.eps", as(eps) preview(on) replace


**Below 50k
*create treatment and control groups
gen above_50=.
replace above_50=0 if rate_spread<7.75&rate_spread>0&loan_amount<50
replace above_50=1 if rate_spread>=7.75&loan_amount<50&rate_spread<12

binscatter rate_spread as_of if as_of>=2010, by(above_50) line(connect) xline(2014) ytitle(Interest Rate Spread) xtitle(Year)/*
*/ legend(label(1 "Rate Spread<7.75") label(2 "Rate Spread>7.75")) ylabel(3(1)10) yscale(r(3 10))
graph export "$figures/figure3_paneld.eps", as(eps) preview(on) replace
